#Notify user of interface state changes

case "$reason" in
	BOUND|REBOOT|STATIC|CARRIER|RELEASE|NOCARRIER|IPV4LL|TIMEOUT|FAIL) ok=1;;
	*) exit ;;
esac

[ -f /etc/dhcpcd_state_notify ] || exit

pidof Xorg || pidof X || exit

export DISPLAY=:0
export TEXTDOMAIN=dhcpcd_notify
export OUTPUT_CHARSET=UTF-8

case "$reason" in
	BOUND|REBOOT|STATIC) #up
		PLACEMENT="bottom"
		BG="green"
		MSG="$(printf "$(gettext '%s acquired on %s')" "$new_ip_address" "$interface")"
		;;
	CARRIER) #ifup
		ssid="$(wpa_cli -i $interface status 2>/dev/null | grep ^ssid | cut -f 2 -d =)"
		PLACEMENT="bottom-left"
		BG="orange"
		MSG="$(printf "$(gettext 'Requesting IP address for %s %s')" "$interface" "$ssid")"
		;;
	RELEASE) #release
		PLACEMENT=bottom
		BG=orange
		MSG="$(printf "$(gettext 'Releasing %s')" "$interface")"
		;;
	NOCARRIER) #down
		PLACEMENT="bottom"
		BG="hotpink"
		MSG="$(printf "$(gettext '%s is down')" "$interface")"
		;;
	IPV4LL|TIMEOUT|FAIL) #timeout
		PLACEMENT="bottom"
		BG="red"
		MSG="$(printf "$(gettext 'IP address request failed on %s')" "$interface")"
		;;
esac

if [ "$MSG" ] ; then
	gtkdialog-splash -placement $PLACEMENT -timeout 4 -bg $BG -text "$MSG"
fi

### END ###
